package com.yhg.qxmall.socket.app;

import java.util.Arrays;
import java.util.Map;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yhg.qxmall.socket.to.SendInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yhg.qxmall.socket.entity.InfoEntity;
import com.yhg.qxmall.socket.service.InfoService;
import com.yhg.common.utils.PageUtils;
import com.yhg.common.utils.R;



/**
 * 
 *
 * @author 凌月青缃
 * @email linyueqingxiang@gmail.com
 * @date 2020-12-17 16:45:37
 */
@RestController
@RequestMapping("socket/info")
public class InfoController {
    @Autowired
    private InfoService infoService;


    //图表显示，返回两部分数据，日期json数组，数量json数组
    @GetMapping("/dataList")
    public R showData() {
        Map<String,Object> map = infoService.getInfoData();
        System.out.println(map);
        return R.ok().put("data",map);
    }

    @PostMapping("/updateBean")
    public R saveBean(@RequestBody String str){

        SendInfo parse =  JSONObject.parseObject(str, SendInfo.class);

        InfoEntity infoEntity = new InfoEntity();
        infoEntity.setId(parse.getId());
        infoEntity.setArea(parse.getArea());
        infoEntity.setTemperature(parse.getTemperature());
        infoEntity.setHumidity(parse.getHumidity());
        infoEntity.setDan(parse.getDan());
        infoEntity.setJia(parse.getJia());
        infoEntity.setLin(parse.getLin());
        infoService.updateById(infoEntity);
        System.out.println(infoEntity);

        return R.ok();
    }
    
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = infoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		InfoEntity info = infoService.getById(id);

        return R.ok().put("info", info);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody InfoEntity info){
		infoService.save(info);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody InfoEntity info){
		infoService.updateById(info);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		infoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
